function [s_jt, share]  = f_share_market( ...
    theta,      ...
    Pi,         ...
    rho,        ...
    x_jt,       ...
    xnonlin_jt, ...
    xi_jt,      ...
    dfull_jt,    ...
    group_ids   ...
)

    delta = x_jt * theta + xi_jt;
    mu    = (xnonlin_jt * Pi) .* dfull_jt;
    dmu   = exp((delta + mu) / (1 - rho));
    
    [xx, yy] = ndgrid(group_ids,1:size(dmu,2));
    sum_dmu = accumarray([xx(:) yy(:)],dmu(:));
    I_i1rt  = (1 - rho) * log(sum_dmu);
    sgroup  = exp(I_i1rt) ./ (1 + exp(I_i1rt));
    expanded_sgroup = sgroup(group_ids, :);
    expanded_sum_dmu = sum_dmu(group_ids, :);
    scond   = dmu ./ expanded_sum_dmu;
    share   = scond .* expanded_sgroup;
    s_jt    = mean(share, 2);

end
